#!/bin/bash

# Test reboot sheepdog without dog shutdown
. ./common

for i in `seq 0 7`; do
    _start_sheep $i
done

_wait_for_sheep 8

_cluster_format -c 6

for i in `seq 0 3`; do
    _vdi_create test$i 100M

    for j in `seq 0 24`; do
	echo "$i $j" | $DOG vdi write test$i $(($j * 4 * 1024 ** 2)) 512
    done &
done
wait

for i in `seq 0 3`; do
    $DOG vdi read test$i | md5sum
done

_reboot_without_dog_shutdown()
{
    local i
    for i in `seq 0 7`; do
	_kill_sheep $i &
    done
    wait

    for i in `seq 0 7`; do
	_start_sheep $i &
    done
    wait

    _wait_for_sheep 8
}

for i in 0 1 2; do
    _reboot_without_dog_shutdown
done

_wait_for_sheep_recovery 0

for i in `seq 0 7`; do
    $DOG cluster info -p 700$i | _filter_cluster_info > $STORE/cinfo.$i
    _vdi_list -p 700$i
    for j in `seq 0 3`; do
	$DOG vdi read test$j -p 700$i | md5sum > $STORE/csum.$i.$j &
    done
    wait
    for j in `seq 0 3`; do
	cat $STORE/csum.$i.$j
    done
done

for i in `seq 1 7`; do
    diff -u $STORE/cinfo.0 $STORE/cinfo.$i
done
